<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\UserSignLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserSignLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserSignLog(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user_id', '用户')->display(function ($user_id) {
                return \App\Models\User::find($user_id)->name ?? '';
            });
            $grid->column('sign_time');
            $grid->column('sign_reward');
            $grid->model()->orderBy('id', 'desc');
            $grid->disableActions();
            $grid->disableCreateButton();
            $grid->disableBatchActions();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserSignLog(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('sign_time');
            $show->field('sign_reward');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserSignLog(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('sign_time');
            $form->text('sign_reward');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
